package com.imay.live.adapter;

import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.imay.live.R;
import com.imay.live.proto.user.UserInfoCard;
import com.imay.live.utils.GlideUtil;

import java.util.List;

/**
 * Created by jeaman on 2017/4/14.
 */

public class LinkMicUserAdapter extends BaseQuickAdapter<UserInfoCard, BaseViewHolder> {
    private UserInfoCard mCheckedUser;

    public LinkMicUserAdapter(List<UserInfoCard> data) {
        super(R.layout.item_link_mic_user, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, UserInfoCard item) {
        boolean visible = false;
        if (mCheckedUser != null && mCheckedUser.uid == item.uid) {
            visible = true;
        }
        helper.setVisible(R.id.link_mic_item_iv_check, visible);

        helper.setText(R.id.link_mic_item_tv_nick, item.nick);
        GlideUtil.loadCircleImage((ImageView) helper.getView(R.id.link_mic_item_iv_avatar), item.imgHead, R.mipmap.pnl_00_head108);
    }

    //选择或者取消选择
    public boolean toggleCheckUser(int position) {
        boolean checked;
        UserInfoCard item = getItem(position);
        if (mCheckedUser != null && mCheckedUser.uid == item.uid) {
            mCheckedUser = null;
            checked = false;
        } else {
            mCheckedUser = item;
            checked = true;
        }
        notifyDataSetChanged();
        return checked;
    }

    public UserInfoCard getCheckedUser() {
        return mCheckedUser;
    }
}
